function integralTermCompany() {
    var _this = this;
    var page;
    _this.obj = null;

    _this.init = function (page_data) {
        page = page_data;
        _this.initTable();
    };

    _this.initTable = function () {
        var list_url = appPath + "/admin/integralTermCompany/queryList";
        page.init("integral_company_form", list_url, "integral_company_table", "integral_company_page", 1, 10);
        page.goPage(1);
        page.list = function (dataList) {
            $("#checkAll").attr("checked", false);
            var len = dataList.length;
            _this.obj = dataList;
            var inner = "", item;
            // 组装数据
            for (var i = 0; i < len; i++) {
                item = dataList[i];
                inner += '<tr>';
                inner += '<td width="50">' + (i + 1) + '</td>';
                inner += '<td >' + item['varName'] + '</td>';
                inner += '<td width="400">' + item['pname'] + '</td>';
                // inner += '<td width="480">' + item['remark'] + '</td>';
                inner += "<td width='450'>";
                // item.id 是积分项Id, 不是单位积分项关系表的Id
                inner += "<a href=javascript:integralTermCompany.view('"+item.id+"') class='a a-view'>详情</a>&nbsp;";
                inner += "<a href=javascript:integralTermCompany.update('"+item.id+"') class='a a-info'>编辑</a>&nbsp;";
                inner += "<a href=javascript:integralTermCompany.delete('"+item.id+"') class='a a-close'>删除</a>&nbsp;";
                inner += "</td>";
                inner += '</tr>';
            }
            return inner;
        }
    };

    _this.view = function (integralId) {
        layer.open({
            type: 2,
            title: '积分项详情',
            area: ['500px', '230px'],		//弹出层大小
            scrollbar: false,				//false隐藏滑动块
            content: [appPath + '/admin/integralTermCompany/detail?deptId='+$("#deptId").val()+'&companyId='+$("#companyId").val()+'&type=3&integralId='+integralId, 'yes']
        });
    }

    _this.update = function (integralId) {
        layer.open({
            type: 2,
            title: '编辑积分项',
            area: ['500px', '300px'],		//弹出层大小
            scrollbar: false,				//false隐藏滑动块
            content: [appPath + '/admin/integralTermCompany/detail?deptId='+$("#deptId").val()+'&companyId='+$("#companyId").val()+'&type=1&integralId='+integralId, 'yes']
        });
    }

    _this.delete = function (integralId) {
        layer.confirm('确定删除？', {
            icon : 3,
            btn: ['确定','取消']        //按钮
        }, function(){
            $.ajax({
                url: appPath + '/admin/integralTermCompany/delete',
                async: false,
                type: 'post',
                data: {
                    'integralId': integralId	            // 当前积分项Id
                },
                success: function(data){
                    var code = data['code'];
                    if(code==10000){

                        layer.msg(data['message'], {icon: 1,  skin: 'layer-ext-moon'});
                        _this.initTable();
                    }else{
                        layer.msg(data['message'], {icon: 2,  skin: 'layer-ext-moon'});
                    }
                }
            });
        },function () {
            //取消
        });

    }

    _this.add = function () {
        layer.open({
            type: 2,
            title: '新增积分项',
            area: ['500px', '300px'],		//弹出层大小
            scrollbar: false,				//false隐藏滑动块
            content: [appPath + '/admin/integralTermCompany/detail?deptId='+$("#deptId").val()+'&companyId='+$("#companyId").val()+'&type=0', 'yes']
        });
    }

    _this.searchAll = function () {
        $("#varName").val("");
        this.initTable();
    }

}

var integralTermCompany = new integralTermCompany();